package com.food.chain.common.util;

import java.io.InputStream;
import java.util.Properties;

/**
 * 读取property文件工具
 */
public class PropertyUtil {
	private final static String FILE_NAME = "config.properties";
	private static Properties property = null;

	static {
		if (null == property) {
			property = new Properties();
		}
		try {
			InputStream in = PropertyUtil.class.getClassLoader().getResourceAsStream(FILE_NAME);
			property.load(in);
			in.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static String getProperty(String key) {
		return property.getProperty(key);
	}

	public static String getProperty(String file_name, String key) {
		if (null == property) {
			property = new Properties();
		}
		try {
			InputStream in = PropertyUtil.class.getClassLoader().getResourceAsStream(file_name);
			property.load(in);
			in.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return property.getProperty(key);
	}

}